#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QColorDialog>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    //创建一个模态颜色对话框
    QColor color = QColorDialog::getColor(QColor(138,43,226),this,"颜色对话框");
    qDebug() <<color;

    //根据用户选择的颜色，设置到按钮上
    char style[1024] = {0};
    snprintf(style,sizeof(style),"background-color: rgb(%d,%d,%d)",color.red(),color.green(),color.blue());
    qDebug() << style;

    //会根据char数组隐式构建一个QString
    ui->pushButton->setStyleSheet(style);
}
